<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "{{%news}}".
 *
 * @property string $newsId
 * @property string $title
 * @property string $content
 * @property integer $createdAt
 */
class News extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%news}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['title', 'content', 'createdAt'], 'required'],
            [['content'], 'string'],
            [['createdAt'], 'integer'],
            [['title'], 'string', 'max' => 20],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'newsId' => '文章ID',
            'title' => 'Title',
            'content' => 'Content',
            'createdAt' => 'Created At',
        ];
    }

    public function beforeValidate()
    {
        if ($this->isNewRecord) {
            $this->createdAt = time();
        }
        return parent::beforeValidate();
    }


}
